#pragma once

using std::string;

struct Util
{
    static int ReadLine(const string &src, size_t &pos, string &dst)
    {
        int i = pos;
        string temp;
        for (; i < src.size(); ++i)
        {
            if (src[i] == '\r' && i + 1 < src.size())
            {
                if (src[i + 1] == '\n') // \r\n
                {
                    ++i;
                    break;
                }
                else // \r
                    break;
            }
            if (src[i] == '\n') // \n
                break;

            temp += src[i];
        }

        if (i == src.size())
        {
            return -1;
        }
        else
        {
            dst += temp;
            pos = i + 1;
            return temp.size();
        }
    }

    static bool CutString(const string &target, string &part1, string &part2, const string &sep)
    {
        size_t pos = target.find(sep);
        if (pos == string::npos)
            return false;
        part1 = target.substr(0, pos);
        part2 = target.substr(pos + sep.size());
        return true;
    }
};